package com.ruoyi.project.wms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.common.zx.PageData;
import com.ruoyi.project.wms.service.impl.WmsGoodsStockLogServiceImpl;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 出入库记录Controller
 *
 * @author zx
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/wms/log")
public class WmsGoodsStockLogController extends BaseController {
    @Autowired
    private WmsGoodsStockLogServiceImpl wmsGoodsStockLogService;

/**
 * 查询出入库记录列表
 */
@PreAuthorize("@ss.hasPermi('wms:log:list')")
@GetMapping("/list")
    public TableDataInfo list() {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> list = wmsGoodsStockLogService.selectWmsGoodsStockLogList(pd);
        return getDataTable(list);
    }

    /**
     * 导出出入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('wms:log:export')")
    @Log(title = "出入库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PageData pd) {
        List<PageData> list = wmsGoodsStockLogService.selectWmsGoodsStockLogList(pd);
        ExcelUtil<PageData> util = new ExcelUtil<PageData>(PageData. class);
        util.exportExcel(response, list, "出入库记录数据");
    }

    /**
     * 获取出入库记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wmsGoodsStockLogService.selectWmsGoodsStockLogById(id));
    }

    /**
     * 新增出入库记录
     */
    @PreAuthorize("@ss.hasPermi('wms:log:add')")
    @Log(title = "出入库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PageData pd) {
        return toAjax(wmsGoodsStockLogService.insertWmsGoodsStockLog(pd));
    }

    /**
     * 修改出入库记录
     */
    @PreAuthorize("@ss.hasPermi('wms:log:edit')")
    @Log(title = "出入库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PageData pd) {
        return toAjax(wmsGoodsStockLogService.updateWmsGoodsStockLog(pd));
    }

    /**
     * 删除出入库记录
     */
    @PreAuthorize("@ss.hasPermi('wms:log:remove')")
    @Log(title = "出入库记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wmsGoodsStockLogService.deleteWmsGoodsStockLogByIds(ids));
    }
}
